package com.atguigu.gmall.product;

import com.atguigu.gmall.common.constant.RedisConst;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan({"com.atguigu.gmall"})
@EnableDiscoveryClient
public class ServiceProductApplication implements CommandLineRunner  {

   // 注入redissonClient
   @Autowired
   private RedissonClient redissonClient;

   public static void main(String[] args) {
      SpringApplication.run(ServiceProductApplication.class, args);
   }

   // 启动时就执行这个方法！ 设置布隆过滤器的误差率。
   @Override
   public void run(String... args) throws Exception {
      // 设置布隆过滤器的误差率
      RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter(RedisConst.SKU_BLOOM_FILTER);
      // 第一个参数传入的是数据规模，第二个参数传递的是误差率
      bloomFilter.tryInit(100000,0.01);

   }
}

